import request from '@/utils/request'
import type { DeviceInfo, DeviceQueryParams, DeviceFormData, DeviceListResponse } from './types'
import { AxiosPromise } from 'axios'

// 查询设备列表
export function getDeviceList(query: DeviceQueryParams): AxiosPromise<DeviceListResponse> {
  return request({
    url: '/protocol/device/list',
    method: 'get',
    params: query
  })
}

// 获取设备详情
export function getDeviceInfo(id: string | number): AxiosPromise<DeviceInfo> {
  return request({
    url: `/protocol/device/${id}`,
    method: 'get'
  })
}

// 新增设备
export function addDevice(data: DeviceFormData): AxiosPromise<void> {
  return request({
    url: '/protocol/device',
    method: 'post',
    data
  })
}

// 修改设备
export function updateDevice(data: DeviceFormData): AxiosPromise<void> {
  return request({
    url: '/protocol/device',
    method: 'put',
    data
  })
}

// 删除设备
export function deleteDevice(id: string | number): AxiosPromise<void> {
  return request({
    url: `/protocol/device/${id}`,
    method: 'delete'
  })
}

// 批量删除设备
export function deleteDevices(ids: (string | number)[]): AxiosPromise<void> {
  return request({
    url: '/protocol/device/batch',
    method: 'delete',
    data: { ids }
  })
}

// 导出设备列表
export function exportDeviceList(query: DeviceQueryParams): AxiosPromise<Blob> {
  return request({
    url: '/protocol/device/export',
    method: 'get',
    params: query,
    responseType: 'blob'
  })
}